package cn.com.dcsgo.controller;

import cn.com.dcsgo.domain.ProdComm;
import cn.com.dcsgo.dto.PageDTO;
import cn.com.dcsgo.dto.ProdCommQueryDTO;
import cn.com.dcsgo.dto.ReviewReplyProdCommDTO;
import cn.com.dcsgo.model.Result;
import cn.com.dcsgo.service.ProdCommService;
import cn.com.dcsgo.vo.ProdCommOverviewVO;
import cn.com.dcsgo.vo.ProdCommVO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 商品评论相关相关接口
 *
 * @author Dcsgo
 * @since 2025/10/23 17:37
 */
@Tag(name = "商品评论相关相关接口")
@RestController
@RequestMapping("prod/prodComm")
public class ProdCommController {
    @Resource
    private ProdCommService prodCommService;

    @GetMapping("page")
    @PreAuthorize("hasAuthority('prod:prodComm:page')")
    @Operation(summary = "分页获取评论")
    public Result<Page<ProdComm>> getPage(PageDTO pageDTO, ProdCommQueryDTO prodCommQueryDTO) {
        return Result.success(prodCommService.getPage(pageDTO, prodCommQueryDTO));
    }

    @GetMapping("{prodCommId}")
    @PreAuthorize("hasAuthority('prod:prodComm:info')")
    @Operation(summary = "获取评论", description = "根据评论ID")
    public Result<ProdComm> getProdComm(@PathVariable Long prodCommId) {
        return Result.success(prodCommService.getById(prodCommId));
    }

    @PutMapping
    @PreAuthorize("hasAuthority('prod:prodComm:update')")
    @Operation(summary = "审核与回复评论")
    public Result<Void> reviewReplyProdComm(@Validated @RequestBody ReviewReplyProdCommDTO reviewReplyProdCommDTO) {
        return Result.handle(prodCommService.reviewReplyProdComm(reviewReplyProdCommDTO));
    }

    @GetMapping("prodComm/prodCommData")
    @Operation(summary = "获取评论统计信息")
    public Result<ProdCommOverviewVO> getProdCommOverviewVO(@RequestParam("prodId") Long prodId) {
        return Result.success(prodCommService.getProdCommOverviewVO(prodId));
    }

    @GetMapping("prodComm/prodCommPageByProd")
    @Operation(summary = "分页获取用户评论信息", description = "评论信息包含用户昵称和头像，evaluate评论筛选参数：-1全部，0好评，1中评，2差评，3带图")
    public Result<Page<ProdCommVO>> getProdCommVOPage(@RequestParam("prodId") Long prodId,
                                                      @RequestParam("evaluate") Integer evaluate,
                                                      PageDTO pageDTO) {
        return Result.success(prodCommService.getProdCommVOPage(prodId, evaluate, pageDTO));
    }
}
